import { navToFace } from '@/utils/face'

let isLoginModalShow = false
let isNotReportShow = false
let isNotFaceShow = false
let isNotUserShow = false
let isErrorShow = false

export function handleNotLogin () {
  if (isLoginModalShow) {
    return
  }
  isLoginModalShow = true
  uni.showModal({
    title: '未登录',
    content: '是否立刻登录？',
    success ({ confirm, cancel }) {
      isLoginModalShow = false
      if (confirm) {
        uni.switchTab({
          url: '/pages/home/index',
        })
      }
      if (cancel) {
        uni.navigateBack()
      }
    },
  })
}

export function handleNotReport () {
  if (isNotReportShow) {
    return
  }
  isNotReportShow = true
  uni.showModal({
    title: '未报到',
    content: '是否立刻报到？',
    success ({ confirm, cancel }) {
      isNotReportShow = false
      if (confirm) {
        uni.navigateTo({
          url: '/pages/report/index',
        })
      }
      if (cancel) {
        uni.navigateBack()
      }
    },
  })
}

export function handleNotFace () {
  if (isNotFaceShow) {
    return
  }
  isNotFaceShow = true
  uni.showModal({
    title: '未实名认证',
    content: '是否立刻实名认证？',
    success ({ confirm, cancel }) {
      isNotFaceShow = false
      if (confirm) {
        navToFace()
      }
      if (cancel) {
        uni.navigateBack()
      }
    },
  })
}

export function handleNotUser () {
  if (isNotUserShow) {
    return
  }
  isNotUserShow = true
  uni.showModal({
    title: '未填写个人信息',
    content: '是否立刻填写个人信息？',
    success ({ confirm, cancel }) {
      isNotUserShow = false
      if (confirm) {
        uni.navigateTo({
          url: '/pages/user/index',
        })
      }
      if (cancel) {
        uni.navigateBack()
      }
    },
  })
}

export function handleNetError () {
  if (isErrorShow) {
    return
  }
  isErrorShow = true
  uni.showModal({
    title: '错误',
    content: '网络错误，请稍后再试',
    showCancel: false,
    success ({ confirm, cancel }) {
      isErrorShow = false
    },
  })
}
